package com.symbio.ishenapi.doctor.controller;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import com.symbio.ishenapi.common.controller.BaseController;
import com.symbio.ishenapi.doctor.model.TmDoctorServerAttribute;
import com.symbio.ishenapi.doctor.model.TmDoctorServerDetails;
import io.jboot.web.controller.annotation.RequestMapping;
import vo.*;

import java.util.*;

@RequestMapping("/TmDoctorServerAttribute")
public class TmDoctorServerAttributController extends BaseController {

    public void saveDoctorServerAttributU(){       //医生添加服务类型
        TmDoctorServerAttribute user = (TmDoctorServerAttribute) getReqBodyObject(TmDoctorServerAttribute.class);
        if (!user.save())
            renderJsonRet(40001);
        else
            renderJsonError(40002);
    }

    public void findDoctorServerAttribut(){       //查看服务
        TmDoctorServerAttribute user = (TmDoctorServerAttribute)getReqBodyObject(TmDoctorServerAttribute.class);
        List<TmDoctorServerAttribute> list=TmDoctorServerAttribute.dao.findTmPatientCount(user);
        renderJsonRet(list);
    }

    public void updTmDoctorServerAttribute(){         //修改医生服务
        TmDoctorServerAttribute user = (TmDoctorServerAttribute) getReqBodyObject(TmDoctorServerAttribute.class);
        TmDoctorServerAttribute u = TmDoctorServerAttribute.dao.findById(user.getId());
        if (!StrKit.isBlank(user.getAttrPrice().toString())) u.setAttrPrice(user.getAttrPrice());
        if (u.update()) {
            renderJsonRet(user.getId());
        } else {
            renderJsonError(40005);
        }
    }

    //****************************************************************************************

    /** GET
     * @Author: chen
     * @Description:根据医生id查询医生拥有的服务
     * @Date: 12:27 2018/12/13
     * @param: [
     *            doctorId      ---医生id 必传
     *            attrType      ---服务类型 传的话查单个服务价格
     *          ]
     * @return: void
     */
    public void findServerById(){
       int doctorId = getParaToInt("doctorId");
       String attrType = getPara("attrType");
       List<TmDoctorServerAttributeVO> data = TmDoctorServerAttribute.dao.findServerById(doctorId,attrType);
       if(data.size()!=0){
           renderJsonRet(data);
       }else {
           renderJsonError(40003,"医生服务");
       }

    }

    /**
     * 医生服务状态更新
     */
    public void updateServerById(){

        try {
            ServerListVO model = (ServerListVO)getReqBodyObject(ServerListVO.class);
            TmDoctorServerAttribute.dao.updateServerById(model);
            renderJsonError(50001,"服务更新");
        }catch (Exception e){
            renderJsonError(50002,"服务更新");
        }
    }

    /**
     *
     *
     * @Author GuoShunYou
     * @Description 查询保险团医生id及对应的保险订单服务次数和类型
     * @date 下午 3:28   2018/11/1
     * @return void
     */
    public void selecServiceAndCount(){
        TmDoctorServerAttribute user = (TmDoctorServerAttribute) getReqBodyObject(TmDoctorServerAttribute.class);
        List<Record> list=TmDoctorServerDetails.dao.getserviCount(user.getId());
        Map map=new HashMap<>();
        map.put("doctorId",user.getId());
        map.put("list",list);
        renderJsonRet(map);
    }


    /**
     * 后台初始化医生的服务
     */
    public void setDefaultServices(){

        ServerListVO model = (ServerListVO)getReqBodyObject(ServerListVO.class);
        try {
            TmDoctorServerAttribute.dao.setDefaultServices(model);
            renderJsonError(50001,"平台设置");
        }catch (Exception e){
            renderJsonError(50002,"平台设置");
        }
    }

    /**
     * 根据医生Id，查询医生的服务状态 回显
     */
    public void findDoctorServerById(){
        try{
            int doctorId = getParaToInt("doctorId");
            DoctorServerVO data = TmDoctorServerAttribute.dao.findDoctorServerById(doctorId);
            renderJsonRet(data);
        }catch (Exception e){
            renderJsonError(40003,"医生服务");
        }
    }


    //*******医生端服务设置***********************************************************************************************

    /**医生服务回显
     * chen
     * doctorId  医生id     attrType  服务类型
     * 2018/11/17
     */
    public void getServerById(){
        try {
            ServerVO serverVO = (ServerVO)getReqBodyObject(ServerVO.class);
            TmDoctorServerAttribute data = TmDoctorServerAttribute.dao.getServerById(serverVO);
            renderJsonRet(data);
        }catch (Exception e){
            renderJsonError(50002,"服务回显查询");
        }
    }

    /** 医生服务设置
     * chen
     * doctorId  医生id     attrType  服务类型
     * id  唯一id   有的话是更新，没有的话是新增
     * attrPrice   服务价格
     * 2018/11/17
     */
    public void setServerById(){
        try {
            ServerVO serverVO = (ServerVO)getReqBodyObject(ServerVO.class);
            TmDoctorServerAttribute.dao.setServerById(serverVO);
            renderJsonError(50001,"服务设置更新");
        }catch (Exception e){
            renderJsonError(50002,"服务设置更新");
        }
    }

    /** 私人医生服务回显
     *  chen
     *  doctorId  医生id   attrType  服务类型:私人医生服务
     *  serverType  私人医生服务下包含的子服务
     *  2018/11/17
     */
    public void getDoctorServerById(){
        try {
            ServerVO serverVO = (ServerVO)getReqBodyObject(ServerVO.class);
            TmDoctorServerDetails data = TmDoctorServerDetails.dao.getDoctorServerById(serverVO);
            renderJsonRet(data);
        }catch (Exception e){
            renderJsonError(50002,"私人医生服务回显");
        }
    }

    /**私人医生服务设置
     * doctorId  医生id   attrType  服务类型:私人医生服务
     *  id  唯一id   有的话是更新，没有的话是新增
     *  serverType  私人医生服务下包含的子服务
     *  serverCount 子服务次数
     */
    public void setDoctorServerById(){
        try {
            ServerVO serverVO = (ServerVO)getReqBodyObject(ServerVO.class);
            TmDoctorServerDetails.dao.setDoctorServerById(serverVO);
            renderJsonError(50001,"私人医生设置更新");
        }catch (Exception e){
            renderJsonError(50002,"私人医生设置更新");
        }
    }
    /**
     * @Author jianghy
     * @Description 查询所有医生业务最新定价散点分布图
     * @date 2018/12/5
     * @return void
     */
    public void queryPricingData(){
        List list = new LinkedList();
        //输入查询业务的类型（查询图文、电话、视频、开药4种订单）的Code 180919001,180919002,180919003,180919004
        String attrType = getPara("attrType");
        List list1 = TmDoctorServerAttribute.dao.queryPricingData(attrType);
        for(int i=0;i<list1.size();i++){
            Double[] ints = new Double[2];
            ints[0] = Double.parseDouble(String.valueOf(i));
            ints[1] = Double.parseDouble(String.valueOf(list1.get(i)));
            list.add(ints);
        }
        renderJsonRet(list);
    }

}
